package cn.edu.scau.cmi.liujiaming.chapter10;

import java.io.*;
import java.nio.channels.*;
import java.util.Scanner;
public class Example10_14 {
   public static void main(String args[]) {
      File file=new File("Example10_14.java");
      Scanner scanner = new Scanner(System.in);
      try{ 
          RandomAccessFile input = new RandomAccessFile(file,"rw");
          FileChannel channel = input.getChannel();
          FileLock lock=channel.tryLock(); //����
          System.out.println("����Ҫ��ȥ������:");
          while(scanner.hasNextInt()){
             int m = scanner.nextInt();
             lock.release();                //����
             for(int i=1;i<=m;i++) {
                String str=input.readLine();
                System.out.println(str);
             }
             lock.close();
             lock=channel.tryLock(); //����
             System.out.println("����Ҫ��ȥ������:");
          }
          input.close();
          lock.close();
      }
      catch(IOException event) {
          System.out.println(event);
      }
      
   }
}
